<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\App\WorkRoom\Action\Dashboard;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use MoChat\App\WorkContact\Contract\WorkContactContract;
use MoChat\App\WorkContact\Contract\WorkContactEmployeeContract;
use MoChat\App\WorkContact\Contract\WorkContactRoomContract;
use MoChat\App\WorkEmployee\Contract\WorkEmployeeContract;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Plugin\AutoTag\Action\Dashboard\Traits\AutoContactTag;

/**
 * 群内客户数量.
 *
 * Class BoomContactCount
 * @Controller
 */
class RoomContactCount extends AbstractAction
{
    use AutoContactTag;

    /**
     * @Inject
     * @var WorkEmployeeContract
     */
    protected $workEmployeeContract;

    /**
     * @Inject
     * @var WorkContactEmployeeContract
     */
    protected $workContactEmployeeContract;

    /**
     * @Inject
     * @var WorkContactRoomContract
     */
    protected $workContactRoomService;

    /**
     * @var
     */
    protected $contactTag;

    /**
     * @Inject
     * @var WorkContactContract
     */
    private $workContactContract;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class)
     * })
     * @RequestMapping(path="/dashboard/workRoom/roomContactCount", methods="get")
     */
    public function handle(): array
    {
        $params['roomId'] = (int) $this->request->input('roomId');

        return ['count' => $this->workContactRoomService->countWorkContactRoomsByRoomIdContact($params['roomId'])];
    }

    /**
     * @return string[] 规则
     */
    public function rules(): array
    {
        return [
            'tagIds' => 'required|array',
            'roomId' => 'required|array',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息.
     */
    public function messages(): array
    {
        return [
            'tagIds.required' => '标签id 必传',
            'roomId.required' => '客户群id 必传',
        ];
    }
}
